﻿using PLC.Core.Entities;
using PLC.Interface.SysLogs;
using System.Linq;
using YWM.Application;
using YWM.Application.Linq.Extensions;

namespace PLC.Application.SysLogs.Services
{
    internal class SysLogService : AsyncCrudService<SysLog, SysLogDto, long, SysLogResultRequestDto>, ISysLogService
    {
        protected override IQueryable<SysLog> CreateFilteredQuery(SysLogResultRequestDto input)
        {
            IQueryable<SysLog> queryable = base.CreateFilteredQuery(input)
                .WhereIf(input.AlarmType != null, sl => sl.AlarmType == input.AlarmType)
                .WhereIf(input.StartTime != null, sl => sl.OperationTime >= input.StartTime)
                .WhereIf(input.EndTime != null, sl => sl.OperationTime <= input.EndTime);
            return queryable;
        }
    }
}
